import {loadPoint, loadPointIcon} from '@/hooks/earth/utils';
import { useResourceHelper } from '@/hooks'

class EarthSearchResult{
  constructor(){
    this.viewer = viewer
    // 添加相关图层
    this._layer = new Cesium.CustomDataSource('esrlayer')
    this.viewer.dataSources.add(this._layer)
    this._handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
  }

  enableEvent(c){
    this._handler.setInputAction(function (event) {
      const picked = viewer.scene.pick(event.position, 3, 3)
      if (picked && picked.id && picked.id.entityCollection._owner._name == 'esrlayer') {
        c(event, picked.id)
      }
    }, Cesium.ScreenSpaceEventType.RIGHT_UP);
  }

  getEntityById(id){
    return this._layer.entities.getById(id)
  }

  removeAll(){
    this._layer.entities.removeAll()
    this._handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_UP)
  }

  
  genPoi(datalist){
    const {
        getStaticUrl
    } = useResourceHelper()
    datalist.map(item => {
      // item.geometry.coordinates[]
      item.icon = getStaticUrl(item.icon)
      loadPointIcon(item, 'linePoi.png').then(entity => {
        item['entityid'] = entity.id
        this._layer.entities.add(entity);
      })
      // let entity = loadPoint(item.loc,item.name)
      // let entity = loadPoint(item.loc,item.name)
      // let entity = loadPoint(item.baseInfo.position,item.name)
      // item['entityid'] = entity.id
      // this._layer.entities.add(entity);
    })
  }

  

}

export default EarthSearchResult